﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using Lamex.Library;
using Lamex.Interface;
using System.IO;
using Lamex.Library.CommonClass;
using DevExpress.XtraGrid.Views.Layout;

namespace Lamex.mMES.UI
{
    public partial class frmMES_App_Commonly_Used : frmBaseChild
    {

        //DevExpress GridControl 关于使用CardView的一点小结
        //https://blog.csdn.net/yang472024191/article/details/40536327?depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromBaidu-5&utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromBaidu-5

        public frmMES_App_Commonly_Used()
        {
            InitializeComponent();
        }

        private void frmMES_App_Commonly_Used_Load(object sender, EventArgs e)
        {
            try { base.InitButtons(); } catch { }//初始化标准功能，因要应用于RibbonForm，所以加入异常处理

            //Layout View-Panning
            //https://documentation.devexpress.com/WindowsForms/5787/Controls-and-Libraries/Data-Grid/Views/Card-and-Layout-Views/Layout-View#panning

            //顶部显示模式面板
            //layoutView1.OptionsView.ShowHeaderPanel = false;

            //layoutView1显示模式，未起作用，改为直接设置属性
            //layoutView1.OptionsView.ViewMode = DevExpress.XtraGrid.Views.Layout.LayoutViewMode.Carousel;

            //设置内嵌式导航器
            //Run Designer-Feature Browser-Focus,...-Embedded Navigator-UseEmbedded Navigator=True

            //使用layoutView1平移功能
            //layoutView1.OptionsBehavior.AllowPanCards = true;//系统默认值
            //layoutView1.OptionsHeaderPanel.ShowPanButton = true;//系统默认值

            //GridView加载数据
            string path = @"\\tx-fs10\TX-FS1\LAMEX\MES\AppMgmt\Icon";

            List<object> list = new List<object>();
            list.Add(new { AppName = "MES", IconName = SaveImage(path + @"\MES.png") });
            list.Add(new { AppName = "MINDMASTER", IconName = SaveImage(path + @"\Mindmaster.png") });

            list.Add(new { AppName = "Excel", IconName = SaveImage(path + @"\Excel.jpg") });
            list.Add(new { AppName = "Word", IconName = SaveImage(path + @"\Word.jpg") });
            list.Add(new { AppName = "PPT", IconName = SaveImage(path + @"\PPT.jpg") });
            list.Add(new { AppName = "OUTLOOK", IconName = SaveImage(path + @"\Outlook.jpg") });

            list.Add(new { AppName = "SAP", IconName = SaveImage(path + @"\SAP.png") });
            list.Add(new { AppName = "AUTOCAD", IconName = SaveImage(path + @"\AutoCad.png") });
            list.Add(new { AppName = "CREO", IconName = SaveImage(path + @"\Creo.png") });
            list.Add(new { AppName = "SOLIDWORKS", IconName = SaveImage(path + @"\SW.jpg") });

            list.Add(new { AppName = "VISUAL STUDIO", IconName = SaveImage(path + @"\VisualStudio.png") });
            list.Add(new { AppName = "DEV EXPRESS", IconName = SaveImage(path + @"\DEV.png") });
            list.Add(new { AppName = "SQL SERVER", IconName = SaveImage(path + @"\SSMS.png") });

            list.Add(new { AppName = "NOTEPAD", IconName = SaveImage(path + @"\Note.jpg") });
            list.Add(new { AppName = "CALCULATOR", IconName = SaveImage(path + @"\CAL.png") });
            list.Add(new { AppName = "PAINT", IconName = SaveImage(path + @"\Paint.png") });
            list.Add(new { AppName = "SnippingTool", IconName = SaveImage(path + @"\Snipping.jpg") });

            list.Add(new { AppName = "EDGE", IconName = SaveImage(path + @"\Edge.png") });

            list.Add(new { AppName = "IMAWOP", IconName = SaveImage(path + @"\IMAWOP.bmp") });
            list.Add(new { AppName = "HPO", IconName = SaveImage(path + @"\HPO.png") });
            list.Add(new { AppName = "PuH", IconName = SaveImage(path + @"\BAT2473.png") });
            list.Add(new { AppName = "TPA", IconName = SaveImage(path + @"\TPA.png") });
            list.Add(new { AppName = "TREPAN", IconName = SaveImage(path + @"\Trepan.png") });

            gridControl1.DataSource = list;

            //在设计模式下，选[LAYOUT]，右键调整图片显示字段的[BestFit]属性，即可卡片实现图片大小自适应

        }

        public byte[] SaveImage(String path)
        {
            FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read); //将图片以文件流的形式进行保存
            BinaryReader br = new BinaryReader(fs);
            byte[] imgBytesIn = br.ReadBytes((int)fs.Length); //将流读入到字节数组中
            return imgBytesIn;
        }

        public override void DoView(IButtonInfo sender)
        {
            //btnRefresh_Click(null, null);
            base.DoView(sender);
        }

        private void layoutView1_CardClick(object sender, DevExpress.XtraGrid.Views.Layout.Events.CardClickEventArgs e)
        {
            string strPC_Name = SystemInformation.ComputerName;

            //C:\Program Files (x86)\Adobe\Acrobat 8.0\Acrobat\Acrobat.exe

            switch (e.RowHandle)
            {
                case 0:
                    break;
                case 1:
                    if (strPC_Name == "BLYZQF2")
                    {
                        MdiTools.OpenIE(@"C:\Program Files (x86)\MindMaster\MindMaster.exe");
                    }
                    else
                    {
                        MdiTools.OpenIE(@"C:\Program Files (x86)\Edrawsoft\Edraw MindMaster（简体中文）\MindMaster.exe");
                    }

                    break;
                case 2:
                    MdiTools.OpenIE(@"C:\Program Files (x86)\Microsoft Office\Office12\EXCEL.exe");
                    break;
                case 3:
                    MdiTools.OpenIE(@"C:\Program Files (x86)\Microsoft Office\Office12\WINWORD.exe");
                    break;
                case 4:
                    MdiTools.OpenIE(@"C:\Program Files (x86)\Microsoft Office\Office12\POWERPNT.exe");
                    break;
                case 5:
                    MdiTools.OpenIE(@"C:\Program Files (x86)\Microsoft Office\Office12\OUTLOOK.exe");
                    break;

                case 6:
                    MdiTools.OpenIE(@"C:\Program Files (x86)\SAP\FrontEnd\SAPgui\saplogon.exe");
                    break;
                case 7:
                    MdiTools.OpenIE(@"C:\Program Files\Autodesk\AutoCAD 2019\acad.exe");
                    break;
                case 8:
                    MdiTools.OpenIE(@"C:\Program Files\PTC\Creo 5.0.5.0\Parametric\bin\parametric.exe");
                    break;
                case 9:
                    MdiTools.OpenIE(@"C:\Program Files\SOLIDWORKS Corp\SOLIDWORKS\SLDWORKS.exe");
                    break;

                case 10:
                    MdiTools.OpenIE(@"C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\devenv.exe");
                    break;
                case 11:
                    MdiTools.OpenIE(@"C:\Users\Public\Documents\DevExpress Demos 19.1\Components\Components\Bin\DevExpress.DemoCenter.v19.1.exe");
                    break;
                case 12:
                    MdiTools.OpenIE(@"C:\Program Files (x86)\Microsoft SQL Server\140\Tools\Binn\ManagementStudio\Ssms.exe");
                    break;

                case 13:
                    System.Diagnostics.Process.Start("notepad.exe"); 
                    break;
                case 14:
                    System.Diagnostics.Process.Start("calc.exe");
                    break;
                case 15:
                    System.Diagnostics.Process.Start("paint.exe");
                    break;
                case 16:
                    System.Diagnostics.Process.Start("snipper.exe");
                    break;
                case 17:
                    //无法启用
                    MdiTools.OpenIE(@"C:\Windows\SystemApps\Microsoft.MicrosoftEdge_8wekyb3d8bbwe\MicrosoftEdge.exe");
                    //System.Diagnostics.Process.Start(@"C:\Windows\SystemApps\Microsoft.MicrosoftEdge_8wekyb3d8bbwe\MicrosoftEdge.exe");
                    break;
            }
        }
    }
}